package com.awan.adapter;

import java.util.ArrayList;
import com.awan.controller.UserItem;
import com.awan.holder.UserItemHolder;
import com.awan.utils.Constanta;
import com.beem.project.beem.R;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class UserListAdapter extends ArrayAdapter<UserItem> {
	
	private ArrayList<UserItem> items;
	private LayoutInflater mInflater;
	private Activity activity;

	public UserListAdapter(Activity a,Context context,int textResourceId,ArrayList<UserItem> items) {
		super(context,textResourceId,items);
		this.items=items;
		this.activity=a;
		mInflater=LayoutInflater.from(context);
	}
	
	public View getView(int arg0, View convertView, ViewGroup arg2) {
		// TODO Auto-generated method stub
		UserItemHolder holder;
		if (convertView==null) {
			convertView=mInflater.inflate(R.layout.contactlistongrid, null);
			
			holder=new UserItemHolder();
			holder.username=(TextView)convertView.findViewById(R.id.contactlistpseudo);
			holder.avatar=(ImageView)convertView.findViewById(R.id.avatar);
			convertView.setTag(holder);
			
		} else {
			holder=(UserItemHolder)convertView.getTag();
		}
		UserItem vi=items.get(arg0);
		holder.username.setText(vi.username);
		holder.avatar.setTag(vi.avatar);
		
		String avatarUrl = Constanta.apiPath+"/"+vi.avatar;
		Log.e(getClass().getSimpleName(), "avatarurl:"+avatarUrl);
		
		//ContactList.imageManager.displayImage(avatarUrl, activity, holder.avatar, R.drawable.no_avatar);
		
		UserItem di=new UserItem();
		di.username=vi.username;
		di.userId=vi.userId;
		di.fullName=vi.fullName;
		di.gender=vi.gender;
		di.onLine=vi.onLine;
		di.avatar=vi.avatar;
		
		convertView.setTag(R.id.detailTag, di);
		return convertView;
	}
	
}
